<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>JUC并发编程 | 学习笔记</title>
    <meta name="generator" content="VuePress 1.9.10">
    <link rel="icon" href="/favicon.ico">
    <script charset="utf-8" async="async" src="/js/jquery.min.js"></script>
    <script charset="utf-8" async="async" src="/js/global.js"></script>
    <script charset="utf-8" async="async" src="/js/fingerprint2.min.js"></script>
    <script>
              var _hmt = _hmt || [];
              (function() {
                var hm = document.createElement("script");
                hm.src = "https://hm.baidu.com/hm.js?0b31b4c146bf7126aed5009e1a4a11c8";
                var s = document.getElementsByTagName("script")[0];
                s.parentNode.insertBefore(hm, s);
              })();
            </script>
    <meta name="description" content="记录学习笔记、项目心得、趟过的雷、踩过的坑">
    <meta property="article:modified_time" content="2023-12-10T16:09:27.000Z">
    <meta property="og:title" content="JUC并发编程">
    <meta property="og:type" content="article">
    <meta property="og:url" content="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html">
    <meta name="twitter:title" content="JUC并发编程">
    <meta name="twitter:url" content="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html">
    <meta name="twitter:card" content="summary_large_image">
    <meta name="robots" content="all">
    <meta name="author" content="青山">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta name="keywords" content="学习笔记, DDD抽奖系统，数据结构，重学Java设计模式, 字节码编程, 中间件, 手写Spring, 手写MyBatis，Java基础, 面经手册，面试题，API网关，SpringBoot Stater">
    <meta name="apple-mobile-web-app-capable" content="yes">
    
    <link rel="preload" href="/assets/css/0.styles.4e2267cf.css" as="style"><link rel="preload" href="/assets/css/styles.css?v=1722145213052" as="style"><link rel="preload" href="/assets/js/cg-styles.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-app.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-4.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-55.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-2.js?v=1722145213052" as="script"><link rel="preload" href="/assets/js/cg-25.js?v=1722145213052" as="script">
    <link rel="stylesheet" href="/assets/css/0.styles.4e2267cf.css"><link rel="stylesheet" href="/assets/css/styles.css?v=1722145213052">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/" class="home-link router-link-active"><!----> <span class="site-name">学习笔记</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/md/nav/nav.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="读书&amp;笔记" class="dropdown-title"><span class="title">读书&amp;笔记</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/book/Java Multithread Programming/Java多线程编程核心技术（第3版）.html" class="nav-link">
  Java多线程编程核心技术（第3版）
</a></li><li class="dropdown-subitem"><a href="/md/book/OnJava中文版基础/第一章.html" class="nav-link">
  On Java 中文版 基础
</a></li><li class="dropdown-subitem"><a href="/md/sad/必修2-计算机基础.html" class="nav-link">
  架构师
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><span class="title">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java 基础
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/core/HelloJava.html" class="nav-link">
  Hello Java
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-变量.html" class="nav-link">
  Java 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-面向对象.html" class="nav-link">
  Java 面向对象
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/jvm/JVM-基础-类字节码详解.html" class="nav-link">
  JVM 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/jvm/GC-Java-垃圾回收基础知识.html" class="nav-link">
  GC
</a></li></ul></li><li class="dropdown-item"><h4>
          JUC
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/JUC并发编程.html" class="nav-link">
  JUC并发编程
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Spring" class="dropdown-title"><span class="title">Spring</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Spring
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Boot
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Cloud
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Security
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Session
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Data
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Batch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java框架" class="dropdown-title"><span class="title">Java框架</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Mybatis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MybatisPlus
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          日志框架
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          缓存
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          连接池
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          ShardingSphere
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="设计模式&amp;算法" class="dropdown-title"><span class="title">设计模式&amp;算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          设计模式
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/参考资料.html" class="nav-link">
  参考资料
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/设计模式七大原则.html" class="nav-link">
  设计模式七大原则
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/UML图.html" class="nav-link">
  UML图
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/Java设计模式.html" class="nav-link">
  Java设计模式
</a></li></ul></li><li class="dropdown-item"><h4>
          算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><span class="title">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Oracle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Redis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Elasticsearch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Kafka
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Mongodb
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Tomcat
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Nginx
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          RabbitMQ
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-简介.html" class="nav-link">
  Docker 简介
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-常用命令.html" class="nav-link">
  Docker 常用命令
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-镜像.html" class="nav-link">
  Docker 镜像
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-数据卷.html" class="nav-link">
  Docker 数据卷
</a></li></ul></li><li class="dropdown-item"><h4>
          K8s
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Git
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Maven
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Gradle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Idea
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/idea/插件.html" class="nav-link">
  插件
</a></li><li class="dropdown-subitem"><a href="/md/idea/常用设置.html" class="nav-link">
  常用设置
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="环境部署" class="dropdown-title"><span class="title">环境部署</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/db/mysql/MySQL-安装.html" class="nav-link">
  MySQL 安装
</a></li></ul></li><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="源码仓库" class="dropdown-title"><span class="title">源码仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/YiShanQingF/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhufanjia/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/md/nav/nav.html" class="nav-link">
  导航
</a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="读书&amp;笔记" class="dropdown-title"><span class="title">读书&amp;笔记</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/book/Java Multithread Programming/Java多线程编程核心技术（第3版）.html" class="nav-link">
  Java多线程编程核心技术（第3版）
</a></li><li class="dropdown-subitem"><a href="/md/book/OnJava中文版基础/第一章.html" class="nav-link">
  On Java 中文版 基础
</a></li><li class="dropdown-subitem"><a href="/md/sad/必修2-计算机基础.html" class="nav-link">
  架构师
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java" class="dropdown-title"><span class="title">Java</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Java 基础
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/core/HelloJava.html" class="nav-link">
  Hello Java
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-变量.html" class="nav-link">
  Java 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/core/Java-基础-面向对象.html" class="nav-link">
  Java 面向对象
</a></li></ul></li><li class="dropdown-item"><h4>
          JVM
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/jvm/JVM-基础-类字节码详解.html" class="nav-link">
  JVM 基础
</a></li><li class="dropdown-subitem"><a href="/md/java/jvm/GC-Java-垃圾回收基础知识.html" class="nav-link">
  GC
</a></li></ul></li><li class="dropdown-item"><h4>
          JUC
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/JUC并发编程.html" class="nav-link">
  JUC并发编程
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Spring" class="dropdown-title"><span class="title">Spring</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Spring
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Boot
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Cloud
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Security
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Session
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Data
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Spring Batch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="Java框架" class="dropdown-title"><span class="title">Java框架</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Mybatis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MybatisPlus
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          日志框架
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          缓存
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          连接池
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          ShardingSphere
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="设计模式&amp;算法" class="dropdown-title"><span class="title">设计模式&amp;算法</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          设计模式
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/designPattern/参考资料.html" class="nav-link">
  参考资料
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/设计模式七大原则.html" class="nav-link">
  设计模式七大原则
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/UML图.html" class="nav-link">
  UML图
</a></li><li class="dropdown-subitem"><a href="/md/designPattern/Java设计模式.html" class="nav-link">
  Java设计模式
</a></li></ul></li><li class="dropdown-item"><h4>
          算法
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="数据库" class="dropdown-title"><span class="title">数据库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Oracle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Redis
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Elasticsearch
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Kafka
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Mongodb
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="中间件" class="dropdown-title"><span class="title">中间件</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Tomcat
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Nginx
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          RabbitMQ
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="开发工具" class="dropdown-title"><span class="title">开发工具</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-简介.html" class="nav-link">
  Docker 简介
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-常用命令.html" class="nav-link">
  Docker 常用命令
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-镜像.html" class="nav-link">
  Docker 镜像
</a></li><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-数据卷.html" class="nav-link">
  Docker 数据卷
</a></li></ul></li><li class="dropdown-item"><h4>
          K8s
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Git
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Maven
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Gradle
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/java/juc/.html" class="nav-link">
  搬砖中。。。
</a></li></ul></li><li class="dropdown-item"><h4>
          Idea
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/idea/插件.html" class="nav-link">
  插件
</a></li><li class="dropdown-subitem"><a href="/md/idea/常用设置.html" class="nav-link">
  常用设置
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="环境部署" class="dropdown-title"><span class="title">环境部署</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><h4>
          MySQL
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/db/mysql/MySQL-安装.html" class="nav-link">
  MySQL 安装
</a></li></ul></li><li class="dropdown-item"><h4>
          Docker
        </h4> <ul class="dropdown-subitem-wrapper"><li class="dropdown-subitem"><a href="/md/devops/docker/Docker-安装.html" class="nav-link">
  Docker 安装
</a></li></ul></li></ul></div></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="源码仓库" class="dropdown-title"><span class="title">源码仓库</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="https://github.com/YiShanQingF/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Github
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li><li class="dropdown-item"><!----> <a href="https://gitee.com/zhufanjia/LearningNotes" target="_blank" rel="noopener noreferrer" class="nav-link external">
  开源项目 - Gitee
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><section class="sidebar-group depth-0"><p class="sidebar-heading open"><span>Java JUC</span> <!----></p> <ul class="sidebar-links sidebar-group-items"><li><a href="/md/java/juc/JUC并发编程.html" class="active sidebar-link">JUC并发编程</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#什么是-juc" class="sidebar-link">什么是 JUC</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#lock-接口" class="sidebar-link">Lock 接口</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#线程间通信" class="sidebar-link">线程间通信</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#集合的线程安全" class="sidebar-link">集合的线程安全</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#多线程锁" class="sidebar-link">多线程锁</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#callable-接口" class="sidebar-link">Callable 接口</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#juc-三大辅助类-countdownlatch-cyclicbarrier-semaphore" class="sidebar-link">JUC 三大辅助类: CountDownLatch CyclicBarrier Semaphore</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#读写锁-reentrantreadwritelock" class="sidebar-link">读写锁: ReentrantReadWriteLock</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#阻塞队列" class="sidebar-link">阻塞队列</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#threadpool-线程池" class="sidebar-link">ThreadPool 线程池</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#fork-join-框架" class="sidebar-link">Fork/Join 框架</a></li><li class="sidebar-sub-header"><a href="/md/java/juc/JUC并发编程.html#completablefuture" class="sidebar-link">CompletableFuture</a></li></ul></li></ul></section></li></ul> </aside> <div><main class="page"> <div class="theme-default-content content__default"><h1 id="juc并发编程"><a href="#juc并发编程" class="header-anchor">#</a> JUC并发编程</h1> <blockquote><p><a href="https://www.bilibili.com/video/BV1Kw411Z7dF" target="_blank" rel="noopener noreferrer">【尚硅谷】大厂必备技术之JUC并发编程 视频学习<span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></p></blockquote> <h2 id="什么是-juc"><a href="#什么是-juc" class="header-anchor">#</a> 什么是 JUC</h2> <blockquote><p>JUC就是 java.util .concurrent 工具包的简称。这是一个处理线程的工具包，JDK1.5 开始出现的。</p></blockquote> <h3 id="进程与线程"><a href="#进程与线程" class="header-anchor">#</a> 进程与线程</h3> <ul><li><strong>进程（Process）</strong> 进程是正在运行的程序的实例。进程是一个具有一定独立功能的程序关于某个数据集合的一次运行活动。它是操作系统动态执行的基本单元，在传统的操作系统中，进程既是基本的分配单元，也是基本的执行单元。</li> <li><strong>线程（thread）</strong> 是操作系统能够进行运算调度的最小单位。它被包含在进程之中，是进程中的实际运作单位。一条线程指的是进程中一个单一顺序的控制流，一个进程中可以并发多个线程，每条线程并行执行不同的任务。</li></ul> <blockquote><p>进程：指在系统中正在运行的一个应用程序；程序一旦运行就是进程；进程——资源分配的最小单位。</p> <p>线程：系统分配处理器时间资源的基本单元，或者说进程之内独立执行的一个单元执行流。线程——程序执行的最小单位。</p></blockquote> <h3 id="线程状态"><a href="#线程状态" class="header-anchor">#</a> 线程状态</h3> <p><img alt="" data-src="/images/java/juc/Java%E7%BA%BF%E7%A8%8B%E7%8A%B6%E6%80%81%E6%B5%81%E8%BD%AC.png" loading="lazy" class="lazy"></p> <p><strong>wait/sleep 的区别</strong></p> <ul><li>sleep 是 Thread 的静态方法，wait 是 Object 的方法，任何对象实例都能调用。</li> <li>sleep 不会释放锁，它也不需要占用锁。wait 会释放锁，但调用它的前提是当前线程占有锁(即代码要在 synchronized 中)。</li> <li>它们都可以被 interrupted 方法中断。</li></ul> <h3 id="并发与并行"><a href="#并发与并行" class="header-anchor">#</a> 并发与并行</h3> <ol><li><strong>串行模式</strong>串行是一次只能取得一个任务，并执行这个任务。</li> <li><strong>并行模式</strong>同时取得多个任务，并同时去执行所取得的这些任务。</li> <li><strong>并发(concurrent)</strong> 指的是多个程序可以同时运行的现象，更细化的是多进程可以同时运行或者多指令可以同时运行。</li></ol> <blockquote><p>在描述并发的时候也不会去扣这种字眼是否精确，<strong>并发的重点在于它是一种现象</strong>, <strong>并发描述的是多进程同时运行的现象</strong>。但实际上，对于单核心 CPU 来说，同一时刻只能运行一个线程。所以，这里的&quot;同时运行&quot;表示的不是真的同一时刻有多个线程运行的现象，这是并行的概念，而是提供一种功能让用户看来多个程序同时运行起来了，但实际上这些程序中的进程不是一直霸占 CPU 的，而是执行一会停一会。</p></blockquote> <h3 id="管程"><a href="#管程" class="header-anchor">#</a> 管程</h3> <ul><li>管程(monitor)是保证了同一时刻只有一个进程在管程内活动,即管程内定义的操作在同一时刻只被一个进程调用(由编译器实现).但是这样并不能保证进程以设计的顺序执行</li> <li>JVM 中同步是基于进入和退出管程(monitor)对象实现的，每个对象都会有一个管程(monitor)对象，管程(monitor)会随着 java 对象一同创建和销毁</li> <li>执行线程首先要持有管程对象，然后才能执行方法，当方法完成之后会释放管程，方法在执行时候会持有管程，其他线程无法再获取同一个管程</li></ul> <h3 id="用户线程和守护线程"><a href="#用户线程和守护线程" class="header-anchor">#</a> 用户线程和守护线程</h3> <ul><li><strong>用户线程:</strong> 平时用到的普通线程,自定义线程</li> <li><strong>守护线程:</strong> 运行在后台,是一种特殊的线程,比如垃圾回收</li> <li><strong>当主线程结束后,用户线程还在运行,JVM 存活</strong></li> <li><strong>如果没有用户线程,都是守护线程,JVM 结束</strong></li></ul> <h2 id="lock-接口"><a href="#lock-接口" class="header-anchor">#</a> Lock 接口</h2> <h3 id="synchronized"><a href="#synchronized" class="header-anchor">#</a> Synchronized</h3> <h3 id="什么是-lock"><a href="#什么是-lock" class="header-anchor">#</a> 什么是 Lock</h3> <h3 id="reentrantlock"><a href="#reentrantlock" class="header-anchor">#</a> ReentrantLock</h3> <h3 id="readwritelock"><a href="#readwritelock" class="header-anchor">#</a> ReadWriteLock</h3> <h3 id="小结-重点"><a href="#小结-重点" class="header-anchor">#</a> 小结(重点)</h3> <h2 id="线程间通信"><a href="#线程间通信" class="header-anchor">#</a> 线程间通信</h2> <h2 id="集合的线程安全"><a href="#集合的线程安全" class="header-anchor">#</a> 集合的线程安全</h2> <h2 id="多线程锁"><a href="#多线程锁" class="header-anchor">#</a> 多线程锁</h2> <h2 id="callable-接口"><a href="#callable-接口" class="header-anchor">#</a> Callable 接口</h2> <h2 id="juc-三大辅助类-countdownlatch-cyclicbarrier-semaphore"><a href="#juc-三大辅助类-countdownlatch-cyclicbarrier-semaphore" class="header-anchor">#</a> JUC 三大辅助类: CountDownLatch CyclicBarrier Semaphore</h2> <h2 id="读写锁-reentrantreadwritelock"><a href="#读写锁-reentrantreadwritelock" class="header-anchor">#</a> 读写锁: ReentrantReadWriteLock</h2> <h2 id="阻塞队列"><a href="#阻塞队列" class="header-anchor">#</a> 阻塞队列</h2> <h2 id="threadpool-线程池"><a href="#threadpool-线程池" class="header-anchor">#</a> ThreadPool 线程池</h2> <h2 id="fork-join-框架"><a href="#fork-join-框架" class="header-anchor">#</a> Fork/Join 框架</h2> <h2 id="completablefuture"><a href="#completablefuture" class="header-anchor">#</a> CompletableFuture</h2></div> <!----> <footer class="page-edit"><div class="edit-link"><a href="https://github.com/YiShanQingF/LearningNotes/edit/master/docs/md/java/juc/JUC并发编程.md" target="_blank" rel="noopener noreferrer">在 GitHub 上编辑此页</a> <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></div> <div class="last-updated"><span class="prefix">上次更新: </span> <span class="time">2023/12/11</span></div></footer> <!----> </main></div> <aside class="page-sidebar"> <div class="page-side-toolbar"><div class="option-box-toc-fixed"><div class="toc-container-sidebar"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:650px"><div style="font-weight:bold;text-align:center;">JUC并发编程</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#什么是-juc" class="toc-sidebar-link">什么是 JUC</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#进程与线程" class="toc-sidebar-link">进程与线程</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#线程状态" class="toc-sidebar-link">线程状态</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#并发与并行" class="toc-sidebar-link">并发与并行</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#管程" class="toc-sidebar-link">管程</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#用户线程和守护线程" class="toc-sidebar-link">用户线程和守护线程</a></li></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#lock-接口" class="toc-sidebar-link">Lock 接口</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#synchronized" class="toc-sidebar-link">Synchronized</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#什么是-lock" class="toc-sidebar-link">什么是 Lock</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#reentrantlock" class="toc-sidebar-link">ReentrantLock</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#readwritelock" class="toc-sidebar-link">ReadWriteLock</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#小结-重点" class="toc-sidebar-link">小结(重点)</a></li></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#线程间通信" class="toc-sidebar-link">线程间通信</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#集合的线程安全" class="toc-sidebar-link">集合的线程安全</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#多线程锁" class="toc-sidebar-link">多线程锁</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#callable-接口" class="toc-sidebar-link">Callable 接口</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#juc-三大辅助类-countdownlatch-cyclicbarrier-semaphore" class="toc-sidebar-link">JUC 三大辅助类: CountDownLatch CyclicBarrier Semaphore</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#读写锁-reentrantreadwritelock" class="toc-sidebar-link">读写锁: ReentrantReadWriteLock</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#阻塞队列" class="toc-sidebar-link">阻塞队列</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#threadpool-线程池" class="toc-sidebar-link">ThreadPool 线程池</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#fork-join-框架" class="toc-sidebar-link">Fork/Join 框架</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#completablefuture" class="toc-sidebar-link">CompletableFuture</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box-toc-over"><img src="/images/system/toc.png" class="nozoom"> <span class="show-txt">目录</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="max-height:550px"><div style="font-weight:bold;text-align:center;">JUC并发编程</div> <hr> <div class="toc-box"><ul class="toc-sidebar-links"><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#什么是-juc" class="toc-sidebar-link">什么是 JUC</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#进程与线程" class="toc-sidebar-link">进程与线程</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#线程状态" class="toc-sidebar-link">线程状态</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#并发与并行" class="toc-sidebar-link">并发与并行</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#管程" class="toc-sidebar-link">管程</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#用户线程和守护线程" class="toc-sidebar-link">用户线程和守护线程</a></li></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#lock-接口" class="toc-sidebar-link">Lock 接口</a><ul class="toc-sidebar-sub-headers"><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#synchronized" class="toc-sidebar-link">Synchronized</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#什么是-lock" class="toc-sidebar-link">什么是 Lock</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#reentrantlock" class="toc-sidebar-link">ReentrantLock</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#readwritelock" class="toc-sidebar-link">ReadWriteLock</a></li><li class="toc-sidebar-sub-header"><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#小结-重点" class="toc-sidebar-link">小结(重点)</a></li></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#线程间通信" class="toc-sidebar-link">线程间通信</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#集合的线程安全" class="toc-sidebar-link">集合的线程安全</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#多线程锁" class="toc-sidebar-link">多线程锁</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#callable-接口" class="toc-sidebar-link">Callable 接口</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#juc-三大辅助类-countdownlatch-cyclicbarrier-semaphore" class="toc-sidebar-link">JUC 三大辅助类: CountDownLatch CyclicBarrier Semaphore</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#读写锁-reentrantreadwritelock" class="toc-sidebar-link">读写锁: ReentrantReadWriteLock</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#阻塞队列" class="toc-sidebar-link">阻塞队列</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#threadpool-线程池" class="toc-sidebar-link">ThreadPool 线程池</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#fork-join-框架" class="toc-sidebar-link">Fork/Join 框架</a><ul class="toc-sidebar-sub-headers"></ul></li><li><a href="/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html#completablefuture" class="toc-sidebar-link">CompletableFuture</a><ul class="toc-sidebar-sub-headers"></ul></li></ul></div></div></div></div></div> <div class="option-box"><img src="/images/system/wechat.png" class="nozoom"> <span class="show-txt">手机看</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.9rem">微信扫一扫</span> <img height="180px" src="https://api.qrserver.com/v1/create-qr-code/?data=http://zhufj.com/md/java/juc/JUC%E5%B9%B6%E5%8F%91%E7%BC%96%E7%A8%8B.html" style="margin:10px;">
              可以<b>手机看</b>或分享至<b>朋友圈</b></div></div></div></div> <div class="option-box"><a title="点击切换全屏" style="text-align:center;padding-left:2px;"><img src="/images/system/full.png" width="30px" class="nozoom"> <span style="color:gray;font-size:11px;font-weight:400;">全屏看</span></a></div> <div class="option-box"><img src="/images/system/toggle.png" width="30px" class="nozoom"> <span class="show-txt">左栏</span></div> <div class="option-box"><img src="/images/system/download.png" width="25px" class="nozoom"> <span class="show-txt">下资料</span> <div class="toc-container"><div class="pos-box"><div class="icon-arrow"></div> <div class="scroll-box" style="text-align:center"><span style="font-size:0.8rem;font-weight:bold;">扫描公众号，回复<span style="color:red;">“1024”</span>下载<span style="color:red;">100GB+</span>大学到毕业分阶段学习技术资料、PDF书籍、实战项目、简历模板等「无任何套路」</span> <img src="/images/personal/qrcode.jpg" height="180px" style="margin:10px;"> <b>公众号:</b> BJCoder
            </div></div></div></div> <!----> <!----></div>  <div class="page-side-sitemap"><div class="option-box"><img src="/images/system/sitemap.png" class="nozoom img"> <span class="show-txt">站点图</span> <div class="sitemap-container"><h4>站点导航图</h4> <table class="sitemap-table"><tr><td nowrap="nowrap"><div class="sitemap-col-group">常用搜索</div></td> <td><div class="sitemap-col-item"><a href="http://www.baidu.com/" target="_blank" title="百度">  
          百度
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.google.com/" target="_blank" title="Google">  
          Google
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.bing.com/" target="_blank" title="Bing">  
          Bing
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://github.com" target="_blank" title="Github">  
          Github
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.programcreek.com/java-api-examples/index.php" target="_blank" title="搜代码">  
          搜代码
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div></td> <!----></tr><tr><td nowrap="nowrap"><div class="sitemap-col-group">技术社区</div></td> <td><div class="sitemap-col-item"><a href="http://www.csdn.net/" target="_blank" title="CDSN">  
          CDSN
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="http://www.cnblogs.com/" target="_blank" title="博客园">  
          博客园
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.oschina.net" target="_blank" title="OSChina">  
          OSChina
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://segmentfault.com/" target="_blank" title="思否">  
          思否
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://juejin.im" target="_blank" title="掘金">  
          掘金
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.linuxidc.com/" target="_blank" title="Linux公社">  
          Linux公社
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://www.ibm.com/developerworks/cn/" target="_blank" title="IBM 开发者">  
          IBM 开发者
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div><div class="sitemap-col-item"><a href="https://stackoverflow.com" target="_blank" title="StackOverflow">  
          StackOverflow
          <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg></a></div></td> <!----></tr></table></div></div></div> <!----> </aside></div><div class="global-ui"><div class="pay-read-more-wrap" style="display:none;position:absolute;bottom:0px;z-index:9999;width:100%;margin-top:-100px;font-family:PingFangSC-Regular, sans-serif;"><div id="pay-read-more-mask" style="position: relative; height: 200px; background: -webkit-gradient(linear, 0 0%, 0 100%, from(rgba(255, 255, 255, 0)), to(rgb(255, 255, 255)));"></div> <a id="pay-read-more-btn" target="_blank" style="position: absolute; left: 50%; top: 70%; bottom: 30px; transform: translate(-50%, -50%); width: 160px; height: 36px; line-height: 36px; font-size: 15px; text-align: center; border: 1px solid rgb(222, 104, 109); color: rgb(222, 104, 109); background: rgb(255, 255, 255); cursor: pointer; border-radius: 6px;">付费阅读</a></div></div></div>
    <script src="/assets/js/cg-styles.js?v=1722145213052" defer></script><script src="/assets/js/cg-4.js?v=1722145213052" defer></script><script src="/assets/js/cg-55.js?v=1722145213052" defer></script><script src="/assets/js/cg-2.js?v=1722145213052" defer></script><script src="/assets/js/cg-25.js?v=1722145213052" defer></script><script src="/assets/js/cg-app.js?v=1722145213052" defer></script>
  </body>
</html>
